package zhihuilan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import zhihuilan.common.enums.RedisKeyEnum;
import zhihuilan.common.utils.RedisCache;
import zhihuilan.entity.MyPunishment;
import zhihuilan.mapper.MyPunishmentMapper;
import zhihuilan.service.MyPunishmentService;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 用户数据 服务实现
 *
 * @author ruoyi
 */
@Service
public class MyPunishmentServiceImpl extends ServiceImpl<MyPunishmentMapper, MyPunishment> implements MyPunishmentService {

    @Resource
    private RedisCache redisCache;

    @Override
    public List<MyPunishment> selectList(Integer staffId, Integer type, Integer shopId) {
        QueryWrapper<MyPunishment> queryWrapper = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(staffId)){
            queryWrapper.eq("staffid", staffId);
        }
        if(!ObjectUtils.isEmpty(type)){
            queryWrapper.eq("type", type);
        }
        if(!ObjectUtils.isEmpty(shopId)){
            queryWrapper.eq("userid", shopId);
        }
        queryWrapper.orderByDesc("create_time");
        List<MyPunishment> result = this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public MyPunishment selectById(Integer id) {
        if(ObjectUtils.isEmpty(id)){
            return null;
        }
        return this.baseMapper.selectById(id);
    }

    @Override
    public MyPunishment addEntity(MyPunishment entity) {
        if (ObjectUtils.isEmpty(entity)) {
            return null;
        }
        if (ObjectUtils.isEmpty(entity.getId())) {
            return null;
        }
        this.baseMapper.insert(entity);
        return entity;
    }
}
